/**
 * 
 */
package com.jolestar.yayaweibotong.util;

import javax.servlet.http.HttpServletRequest;

/**
 * @author jolestar@gmail.com
 * 
 */
public class RequestUtils {

	public static final int getIntParam(HttpServletRequest request,
			String name, int defaultValue) {
		try {
			String value = request.getParameter(name);
			if (value == null) {
				return defaultValue;
			}
			return Integer.parseInt(value);
		} catch (Exception e) {
			return defaultValue;
		}
	}
	
	public static final int getIntHeader(HttpServletRequest request,
			String name, int defaultValue) {
		try {
			String value = request.getHeader(name);
			if (value == null) {
				return defaultValue;
			}
			return Integer.parseInt(value);
		} catch (Exception e) {
			return defaultValue;
		}
	}

	public static final long getLongParam(HttpServletRequest request,
			String name, long defaultValue) {
		try {
			String value = request.getParameter(name);
			if (value == null) {
				return defaultValue;
			}
			return Long.parseLong(value);
		} catch (Exception e) {
			return defaultValue;
		}
	}

	public static final boolean getBooleanParam(HttpServletRequest request,
			String name, boolean defaultValue) {
		try {
			String value = request.getParameter(name);
			if (value == null) {
				return defaultValue;
			}
			return Boolean.parseBoolean(value);
		} catch (Exception e) {
			return defaultValue;
		}
	}

}
